home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / dirent.lha / dirent / testdir.c < prev   
C/C++ Source or Header  |  1988-09-02  |  895b  |  56 lines

  1. /*
  2.     testdir -- basic test for C library directory access routines
  3.  
  4.     last edit:    25-Apr-1987    D A Gwyn
  5. */
  6.  
  7. #include    <sys/types.h>
  8. #include    <stdio.h>
  9. #include    <dirent.h>
  10.  
  11. extern void    exit();
  12. extern int    strcmp();
  13.  
  14. main( argc, argv )
  15.     int            argc;
  16.     register char        **argv;
  17. {
  18.     extern int        errno;
  19.     register DIR        *dirp;
  20.     register struct dirent    *dp;
  21.     int            nerrs = 0;    /* total not found */
  22.  
  23.     if ( (dirp = opendir( "." )) == NULL )
  24.         {
  25.         (void)fprintf( stderr, "Cannot open \".\" directory\n" );
  26.         exit( 1 );
  27.         }
  28.  
  29.     while ( --argc > 0 )
  30.         {
  31.         ++argv;
  32.  
  33.         while ( (dp = readdir( dirp )) != NULL )
  34.             {
  35.             if ( strcmp( dp->d_name, *argv ) == 0 )
  36.                 {
  37.                 (void)printf( "\"%s\" found.\n", *argv );
  38.                 break;
  39.                 }
  40.             }
  41.  
  42.         if ( dp == NULL )
  43.             {
  44.             if (errno)
  45.                 perror("");
  46.             (void)printf( "\"%s\" not found.\n", *argv );
  47.             ++nerrs;
  48.             }
  49.  
  50.         rewinddir( dirp );
  51.         }
  52.  
  53.     (void)closedir( dirp );
  54.     exit( nerrs );
  55. }
  56.